var express = require('express');
var router = express.Router();
var Post = require('../models/posts.js');

router.get('/',function(req,res,next){
  var query = req.query['query'];
  Post.search(query,function(err,posts){
    if(err){
      res.json({success:false,message:'搜索失败'});
    }else if(posts.length){
      res.json({success:true,message:'搜索成功'});

    }else{
      res.json({success:false,message:'没有相应的文章'});

    }
  })
});

module.exports = router;